<form method="post" action="index.php?app=b2c&ctl=admin_goods_cat&act=save" id='add-category-form'>
<div class="tableform">
    <div class="division">
      <table cellpadding="0" cellspacing="0" border="0">
        <tr>
          <th><{t}>分类名称：<{/t}>
            <{if $cat.cat_id }><input type="hidden" value="<{$cat.cat_id}>" name="cat[cat_id]" /></th><{/if}>
          <td><input type="text" value="<{$cat.cat_name|escape:'html'}>" name="cat[cat_name]" vtype='required' class='x-input'/>
            <{$cat_name}></td>
        </tr>
        <tr>
          <th><{t}>上级分类：<{/t}></th>
          <td><{input type="select" name="cat[parent_id]" style="font-size:12px;" required='1' value=$cat.parent_id rows=$catList valueColumn="cat_id" labelColumn="cat_name" onchange="changeCat(this)"}>
            <span class="notice-inline"><{t}>顶级分类请选择“无”<{/t}></span></td>
        </tr>
        <tr>
          <th><{t}>商品类型：<{/t}></th>
          <td><{input type="object_select" object="goods_type@b2c" multiple="true" onlyone="true" rowselect="true" textcol="name" name="cat[type_id][linkid]" linkid=$cat.type_id.linkid obj_name='cat[type_id][info]' value=$cat.type_id.info}></td>
        </tr>
<!--tag_foreign_cat_disable-->
        <tr>
          <th><{t}>模板：<{/t}></th>
          <td id="tmpl_cat">
          <select name="cat[gallery_setting][gallery_template]">
            <option value="0">默认模板</option>
            <{foreach from=$tmpl_info item=item key=key}>
                <option value="<{$item.tmpl_path}>" <{if $gallery_setting.gallery_template==$item.tmpl_path}>  selected<{/if}>><{$item.tmpl_name}></option>
            <{/foreach}>
          </select>
          </td>
        </tr>
        <tr>
          <th><{t}>LOGO：<{/t}></th>
          <td>
                <{input type="image" name="cat[cat_logo]" value=$cat.cat_logo width=160 height=90}>
          </td>
        </tr>

        <tr>
          <th><{t}>排序：<{/t}></th>
          <td><input style="width:50px;" vtype="unsigned" class="inputstyle" value="<{$cat.p_order}>" name="cat[p_order]" class="_x_ipt"/>
            <span class="notice-inline"><{t}>数字越小越靠前<{/t}></span></td>
        </tr>
		<{if $isprofit == 'true'}><tr>
          <th><{t}>交易佣金费率：<{/t}></th>
          <td><input style="width:40px;" vtype="unsigned" class="inputstyle" value="<{$cat.profit_point}>" name="cat[profit_point]" class="_x_ipt"/>%
            <span class="notice-inline"><{t}>交易成功后抽取的佣金比例<{/t}></span></td>
        </tr><{/if}>
        <tr>
          <th><{t}>在前台隐藏：<{/t}></th>
          <td><input type='checkbox' name='cat[hidden]' value='true' <{if $cat.hidden eq 'true'}>checked<{/if}> /></td>
        </tr>
        <tr>
          <th><{t}>TITLE<br>
            (页面标题)<{/t}></th>
          <td><input type="text" name="cat[seo_info][seo_title]" style="width:90%" class="inputstyle" maxlength="100" value="<{$seo_info.seo_title}>"></td>
        </tr>
          <tr>
          <th><{t}>META_KEYWORDS<br>
            (页面关键词)<{/t}></th>
          <td><input type="text" name="cat[seo_info][seo_keywords]" style="width:90%" class="inputstyle" maxlength="100" value="<{$seo_info.seo_keywords}>"></td>
        </tr>
        <tr>
          <th><{t}>META_DESCRIPTION<br>
            (页面描述)<{/t}></th>
          <td><textarea name="cat[seo_info][seo_description]" rows=4 style="width:90%" class="inputstyle" cols=35 maxlength=255/><{$seo_info.seo_description}></textarea></td>
        </tr>

      </table>
    </div>
<!--tag_foreign_cat_seo-->

<!--tag_foreign_goods_cat-->

</div>




<div class="table-action">
	<{button label=$___b2c="保存"|t:'b2c'  type="submit" }>
	<!--
   <{button label="保存并继续添加" type="button" id='easy-save-category'}>
   //-->
	<{button class="btn-secondary " label=$___b2c="取消"|t:'b2c' isclosedialogbtn="true" onclick="W.page('index.php?app=b2c&ctl=admin_goods_cat&act=index')" }>
</div>
<script>
	function changeCat(obj){	
	var selvalue = obj.options[obj.options.selectedIndex].value;
  var cid = $E('#add-category-form input[name^=cat[cat_id]');
  var cat_id = 0;
  if(cid){
    cat_id = cid.value;
  }
		new Request.HTML({
			url:"index.php?app=b2c&ctl=admin_goods_cat&act=changeCat&cat_id="+cat_id+"&select_id="+selvalue,
			method:"get",
			update:$("tmpl_cat"),
		}).send();
	}
</script>
<script>
           $E('#add-category-form input[name^=cat[cat_name]').addEvent('keydown',function(e){

               if(e.key=='enter'){


                 e.stop();

                   return $('easy-save-category').fireEvent('click',{stop:$empty});
               }

           });

           $('add-category-form').store('target',{onComplete:function(){

                  if(gms=$('g_menu_sec_2')){
                      gms.empty();
                      gms.retrieve('update',$empty)();
                  }


           }});

			if($('easy-save-category'))
           $('easy-save-category').addEvent('click',function(e){
                    e.stop();
                    var _form=this.form;

                    var cname=$E('#add-category-form input[name^=cat[cat_name]');
                    var value=cname.get('value').clean().trim();

                    var cid=$E('#add-category-form input[name^=cat[cat_id]');
                    if(cid) cid.remove();

                    if(!value)return MessageBox.error('<{t}>分类名称为不能为空.<{/t}>');
                    if(this.retrieve('tempname',[]).contains(value)){
                       if(!confirm('<{t}>您刚才已经添加了分类:<{/t}>"'+value+'"<{t}>\n要重复添加么?<{/t}>'))return;
                    }

                    this.retrieve('tempname',[]).include(value);

                    if(!$(_form).get('target')){

                      var _target={
                         update:'messagebox'
                      }
                       _form.set('target',JSON.encode(_target));
                    }
                    _form.fireEvent('submit',e).erase('target');

           });
			$('add-category-form').store('target',{
				onComplete:function(){
					if($('add-category-form').getParent('.dialog'))
					$('add-category-form').getParent('.dialog').retrieve('instance').close();
				}
			});
        </script>
		<script>
			if($('selectValue'))$('selectValue').addEvent('keyup',function(){
				var value = $('selectValue').value;
				 new Request.HTML({
					url:'index.php?app=b2c&ctl=admin_goods_cat&act=updataType',
					method:'post',
					update:$('selectType'),
					data:'name='+value,
				 }).send();
			});
			if($('selectValue'))$('selectValue').addEvent('change',function(){
				var value = $('selectValue').value;
				 new Request.HTML({
					url:'index.php?app=b2c&ctl=admin_goods_cat&act=updataType',
					method:'post',
					update:$('selectType'),
					data:'name='+value,
				 }).send();
			});
		</script>
</form>
